﻿using B.S.Data.MES.API.Applications.CangKu.Command;
using B.S.Domain.CangKu;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;
using SqlSugar;

namespace B.S.Data.MES.API.Applications.CangKu.CommandHandlers
{
    public class PDeleKuquCommandHandlers : IRequestHandler<PDeleKuQuCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<CangKuQU> cangRepository;

        public PDeleKuquCommandHandlers(IBaseRepository<CangKuQU> cangRepository)
        {
            this.cangRepository = cangRepository;
        }

        public async Task<APIRequst<int>> Handle(PDeleKuQuCommand request, CancellationToken cancellationToken)
        {
            var list = cangRepository.GetAll().Where(x=>request.Ids.Contains(x.CangKuId)).ToList();
            foreach (var item in list)
            {
                item.isDel = true;
            }
            await cangRepository.UpdateRange(list);
            return new APIRequst<int>
            {
                Code = RequstCode.成功,
                Msg = RequstCode.成功.ToString()
            };
        }
    }
}
